#include "MainWindow.h"
#include "ui_MainWindow.h"
#include <iostream>


MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    this->ui->setupUi(this);

    QUrl urlInFile = QUrl::fromLocalFile("/home/cedric/VEG849.wmv");


    this->playlist.addMedia(urlInFile);
    this->player.setPlaylist(&playlist);

    this->recorder = new QMediaRecorder(&player);
    QVideoEncoderSettings videoEncoderSettings;
    QAudioEncoderSettings audioEncoderSettings;

    videoEncoderSettings.setCodec("video/mpeg2");
    videoEncoderSettings.setResolution(640, 480);
    audioEncoderSettings.setCodec("audio/vorbis");
    audioEncoderSettings.setQuality(QtMultimediaKit::HighQuality);
    this->recorder->setEncodingSettings(audioEncoderSettings, videoEncoderSettings);

    QUrl urlOutFile = QUrl::fromLocalFile("/home/cedric/cuttedVideo.mp2");
    this->recorder->setOutputLocation(urlOutFile);

    this->connect(this->ui->startButton, SIGNAL(clicked()), this, SLOT(start()));
    this->connect(this->ui->stopButton, SIGNAL(clicked()), this, SLOT(stop()));
    //*/
}

MainWindow::~MainWindow()
{
    delete ui;
    delete this->recorder;
}

void MainWindow::start()
{
    recorder->record();
    player.play();
    std::cout << "start" << std::endl;
    //player.setPosition(2000);
}

void MainWindow::stop()
{
    player.stop();
    recorder->stop();
    std::cout << "stop" << std::endl;
}
